<?php
class Config_Abstract
    extends Object
{
    protected function _loadFiles($path)
    {
        if(is_null($path) || empty($path)) {
            throw new Zend_Exception('Empty path to cofig files.');
        }

        $config = array();
        $handle = opendir($path);
        $xml = new Config_Xml();

        while (false !==($name = readdir($handle))) {
            if($name!='.' && $name!='..' && $name!='.svn') {
                $file = simplexml_load_file($path.$name);
                $config = array_merge_recursive($config,$xml->toArray($file));
            }
        }

        closedir($handle);

        return $config;
    }

    public function getConfig($cacheDir,$path)
    {
        $backendOptions = array('cache_dir'=>$cacheDir,'file_name_prefix'=>'config');
        $frontendOption = array('automatic_serialization'=>true);

        $cache = Zend_Cache::factory('Core', 'File',$frontendOption,$backendOptions);
        $config = $cache->load('config');

        if(!is_array($config)) {
            $config = $this->_loadFiles($path);
            $cache->save($config,'config');
        }

        return $config;
    }
}